package com.ss.ttvideoengine.b;

import android.text.TextUtils;

import org.json.JSONException;
import org.json.JSONObject;

public final class VideoInfo {
    public String videoId;
    public String validate;
    public VideoItem mVideoItem1;
    public VideoItem mVideoItem2;
    public VideoItem mVideoItem3;
    public int status;
    public int videoDuration;

    public VideoInfo() {

    }

    public final void initWithJO(JSONObject jsonObject) {
        if (jsonObject != null) {
            JSONObject videoListJo = jsonObject.optJSONObject("video_list");
            this.videoDuration = jsonObject.optInt("video_duration");
            this.status = jsonObject.optInt("status");
            if (videoListJo != null) {
                try {
                    if (videoListJo.has("video_1")) {
                        this.mVideoItem1 = new VideoItem();
                        this.mVideoItem1.initWithJO(videoListJo.getJSONObject("video_1"));
                        this.mVideoItem1.videoDuration = this.videoDuration;
                    }

                    if (videoListJo.has("video_2")) {
                        this.mVideoItem2 = new VideoItem();
                        this.mVideoItem2.initWithJO(videoListJo.getJSONObject("video_2"));
                        this.mVideoItem2.videoDuration = this.videoDuration;
                    }

                    if (videoListJo.has("video_3")) {
                        this.mVideoItem3 = new VideoItem();
                        this.mVideoItem3.initWithJO(videoListJo.getJSONObject("video_3"));
                        this.mVideoItem3.videoDuration = this.videoDuration;
                    }
                } catch (JSONException jsonException) {
                    jsonException.printStackTrace();
                }
            }
            this.validate = jsonObject.optString("validate");
            jsonObject.optBoolean("enable_ssl");
            jsonObject.optString("user_id");
            this.videoId = jsonObject.optString("video_id");
            jsonObject.optString("video_name");
        }
    }

    public final VideoItem selectDefinition(String definition) {
        if (TextUtils.isEmpty(definition)) {
            return this.mVideoItem1;
        } else {
            VideoItem[] videoItems = new VideoItem[3];
            videoItems[0] = this.mVideoItem1;
            videoItems[1] = this.mVideoItem2;
            videoItems[2] = this.mVideoItem3;
            for (int i = 0; i < 3; i++) {
                if (videoItems[i] != null && videoItems[i].definition != null && (videoItems[i].definition.equals(definition))) {
                    return videoItems[i];
                }
            }
            return null;
        }
    }
}

